package com.zr.daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.zr.dao.CktjDao;
import com.zr.model.AttendanceTable;
import com.zr.model.CkUser;
import com.zr.util.JDBCUtil;

public class CktjDaoImpl implements CktjDao{

	@Override
	public int getcount(int eid) {
		int count = 0;
		StringBuffer  sql  = new StringBuffer("");
		sql.append(" select count(id) as number");
		sql.append(" from vacation where eid=?");

		Connection  con = JDBCUtil.getConnection();
		try {
			PreparedStatement  pst = con.prepareStatement(sql.toString());
			pst.setInt(1, eid);
			ResultSet  rs = pst.executeQuery();
			if(rs.next()){
				count = rs.getInt("number");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return count;
	}

	@Override
	public List<CkUser> getcktj(int eid, int page, int rows) {
		List<CkUser> list=new ArrayList<CkUser>(); 
		
		StringBuffer sql = new StringBuffer();
		sql.append("select ename,actualday,category,reason,opinion,remake"); 
		sql.append(" from vacation inner join employee on employee.eid=vacation.eid where employee.eid=?");
		sql.append(" limit ?,?");
		Connection con = JDBCUtil.getConnection();
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			pst.setInt(1, eid);
			pst.setInt(2, (page-1)*rows);
			pst.setInt(3, rows);
			ResultSet rs = pst.executeQuery();
			while(rs.next()){
				CkUser ck=new CkUser();
				ck.setEname(rs.getString("ename"));
				ck.setActualday(rs.getInt("actualday"));
				ck.setCategory(rs.getString("category"));
				ck.setOpinion(rs.getString("opinion"));
				ck.setReason(rs.getString("reason"));
				ck.setRemake(rs.getString("remake"));
				list.add(ck);
			}

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
}
